package com.vonchenchen.renderer;

import android.view.SurfaceView;

/**
 * Created by lidechen on 2021/1/18.
 */
public class FrameRenderer {

    private long mPtr;

    public FrameRenderer(){
        mPtr = RendererNative.createNativeRenderer();
    }

    public void setCanvas(RendererCanvas canvas){
        if(mPtr != 0) {

            RendererNative.setView(mPtr, canvas.view, canvas.mode.getValue(), canvas.name);
            canvas = null;
        }
    }

    public void release(){
        if(mPtr != 0) {
            RendererNative.destoryNativeRenderer(mPtr);
            mPtr = 0;
        }
    }

    public void draw(byte[] data, int width, int height, int length){
        if(mPtr != 0) {
            RendererNative.draw(mPtr, data, width, height, length);
        }
    }

    public long getPtr(){
        return mPtr;
    }

    public void trigger(){
//        if(mPtr != 0){
//            RendererNative.testTrigger(mPtr);
//        }
    }
}
